package controller;

import entity.hotel_employee;
import entity.hotel_room;
import entity.hotel_tenant;
import service.HotelEmployeeService;
import service.HotelOrderService;
import serviceImp.HotelEmployeeServiceImp;
import serviceImp.HotelOrderServiceImp;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * Servlet implementation class EmployeeInfoController
 */
@WebServlet("/order/CheckOutController.do")
public class CheckOutController extends HttpServlet {
	private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public CheckOutController() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=utf-8");
		request.setCharacterEncoding("utf-8");
		String room_no = request.getParameter("room_no");
		String checkOutNo = request.getParameter("checkOutNo");
		HotelOrderService hotelOrderService = new HotelOrderServiceImp();

		hotel_tenant hotel_tenant= hotelOrderService.selectTenantByRoomNo(room_no);

		if(checkOutNo!=null){
			int code = hotelOrderService.roomStatusChange(checkOutNo,"0");
			int count = hotelOrderService.deleteTenant(checkOutNo);
			if(code>0&&count>0){
				request.setAttribute("checkOutTip","退房成功");
				request.getRequestDispatcher("/order/checkOut.jsp").forward(request,response);
			}else{
				request.setAttribute("checkOutTip","退房失败");
				request.getRequestDispatcher("/order/checkOut.jsp").forward(request,response);
			}
		}

		if(hotel_tenant!=null){
			request.setAttribute("hotel_tenant",hotel_tenant);
			request.getRequestDispatcher("/order/checkOut.jsp").forward(request,response);
		}else {
			request.setAttribute("checkOutTip","房间号不存在或房间状态为空");
			request.getRequestDispatcher("/order/checkOut.jsp").forward(request,response);
		}


	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
